package com.lazydong.apiforward.clientupdate.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class JarResFileCopyUtil {
    public static String loadResourceFile(String dir, String fileName) {
        String fileNamePath;
        if (dir == null) {
            fileNamePath = fileName;
        } else {
            fileNamePath = dir + "/" + fileName;
        }
        StringBuilder contentBuilder = new StringBuilder();
        InputStream inputStream = JarResFileCopyUtil.class.getClassLoader().getResourceAsStream(fileNamePath);
        assert inputStream != null;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            String line;
            while ((line = reader.readLine()) != null) {
                contentBuilder.append(line).append(System.lineSeparator());
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return contentBuilder.toString();
    }
}
